/*
 * $Id: ExecutorServices.java 142 2009-05-14 14:59:49Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.gui.deltagui.executor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * ExecutorServices.
 * 
 * @author Andreas Meyer
 * @version $Revision: 142 $
 */
public class ExecutorServices {
	
	/** The executor for component events. */
	private static ExecutorService componentExecutor;

	/** The executor for picture loading. */
	private static ExecutorService pictureLoader;


	static {

		// initialize all executors
		componentExecutor = new ThreadPoolExecutor(
				1,   // core pool size
	            5,  // max pool size
	            300, // keep alive time 
	            TimeUnit.SECONDS,
	            new ArrayBlockingQueue<Runnable>(500),
	            new ThreadPoolExecutor.DiscardOldestPolicy());

		pictureLoader = new ThreadPoolExecutor(
				5,   // core pool size
                25,  // max pool size
                60,  // keep alive time
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100));

	}

	
	/**
	 * Return the component executor.
	 * 
	 * @return
	 */
	public static ExecutorService getComponentExecutor() {
		return componentExecutor;
	}

	/**
	 * Return the picture loader.
	 * 
	 * @return
	 */
	public static ExecutorService getPictureLoader() {
		return pictureLoader;
	}
	
	/**
	 * Stop all executors.
	 */
	public static void shutdown() {
		componentExecutor.shutdown();
		pictureLoader.shutdownNow();
	}

}
